
#ifndef	__SANCAB_AUBIN_HPP_2010__
#define	__SANCAB_AUBIN_HPP_2010__

#include <vector>
#include <string>

#include <db_cxx.h>


#include <boost/thread/mutex.hpp>

#include "binindex.hpp"
#include "filecell.hpp"


namespace   sancab   {

class   Aubin
{

public  :
    Aubin( const std::string& data_root, const std::string& index_file, DbEnv* dbenv_p, u_int32_t n_tables, int32_t slim=0 );
    ~Aubin();

public  :
    int insert( const std::string& kpin,
             const std::string& key,
             const std::string& data );

    int insertAppend( const std::string& kpin,
             const std::string& key,
             const std::string& data );

    int insertIgnore( const std::string& kpin,
             const std::string& key,
             const std::string& data );

    int find( const std::string& kpin,
             const std::string& key,
                   std::string& data );

    int find( const std::string& kpin,
             const std::string&  key,
                   std::vector< std::string >& data,
				   u_int32_t     limit = 0 );

    int erase( const std::string& kpin,
               const std::string& key );

	int	slim( void );

public  :

    virtual int     insertAppend( const std::vector< std::string >& kpin,
                                  const std::vector< std::string >& key,    
                                  const std::vector< std::string >& data );


private :

    const std::string   getSkeyByKpin( const std::string& kpin );

private :

    std::string _data_root;
	DbEnv*		_dbenv_p;

	boost::mutex	_mutex;
	boost::mutex	_mutex_read;
    
private :
	BinIndex	_bin_index;
	FileCell	_filecell;

};  //// class Aubin


}   //// namespace sancab


#endif	////	__SANCAB_AUBIN_HPP_2010__

